import {
    request
} from './request'
import {
    getCookie
} from './cookie'

const baseURL = window.globalData.loginbaseUrl

/* 第一次登陆请求 */
export function loginrequest(form) {
    const params = {
        userName: form.username,
        // password: md5(form.password)
        clientType: 'winpc'
    }
    return request({
        baseURL: baseURL,
        url: '/smc-ac/accounts/authorize',
        method: 'post',
        data: params
    })
}

/* 第二次登陆请求 */
export function loginrequestsecond(form) {
    const params = form
    request.defaults.headers.common['X-Subject-Token'] = getCookie('login_tokens')
    return request({
        baseURL: baseURL,
        url: '/smc-ac/accounts/authorize',
        method: 'post',
        data: params
    })
}

/* 退出登录 */
export function loginOut() {
    return request({
        baseURL: window.globalData.loginbaseUrl,
        url: '/smc-ac/accounts/unauthorize',
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        },
        data: {
            token: getCookie('login_tokens'),
            clientType: 'winpc'
        }
    })
}

/* 得到用户菜单 */
export function getMenu(params) {
    request.defaults.headers.common['X-Subject-Token'] = getCookie('login_tokens')
    return request({
        baseURL: baseURL,
        url: '/composite/app/user/detail',
        method: 'post',
        data: params
    })
}

// 获取用户信息
export function getUserInfo(id) {
    return request({
        url: '/composite/user/det',
        method: 'post',
        data: {
            id
        }
    })
}

// 获取城镇信息
export function getTownShip(params) {
    return request({
        baseURL: baseURL,
        url: '/smart-safety/homepage/gettownship',
        method: 'post',
        data: params
    })
}

/* 得到当前地图地址 */
export function getMapUrl() {
    request.defaults.headers.common['X-Subject-Token'] = getCookie('login_tokens')
    return request({
        baseURL: baseURL,
        url: '/smart-safety/homepage/getMapAddress',
        method: 'get',
        params: {}
    })
}

// 获取行政区划信息
export function getDistrictLevel(params) {
    return request({
        baseURL: baseURL,
        url: '/composite/district/code/det',
        method: 'post',
        data: params
    })
}